#-----------------------------------#
# Replication of:
# Seeking Opportunity in the Knowledge Economy: Moving Places, Moving Politics?
# Valentina Consiglio, Thomas Kurer

# File: 7b_models_mechanisms_PC1

# Note: This file codes the models included in the mechanisms section of the paper based on the Economic component (PC1) of the index. 
# It takes the following steps:
# (1) Main models (as in 5)
# (2) Analysis of symmetry of effects (up- vs. downward moves)
# (3) Analysis of economic and cultural mechanisms
# (4) Analysis of symmetry of economic and cultural mechanisms
# The data is loaded and prepared in 5_models_main_NUTS3; ensure the script was run before this file. 
#-----------------------------------#

#-------------------------------------------------------------------------------# 
#### Preparation ####
#-------------------------------------------------------------------------------# 

## Texreg input 
vec_gof_names <- c("Num. obs." = "N",
                   "Num. groups: pid" = "N individuals",
                   "Num. groups: syear" = "N years")


#-------------------------------------------------------------------------------# 
#### 1 | Main Models with Principal Component Econ (PC1) ####
#-------------------------------------------------------------------------------# 

## Political integration and orientation ##

fe_main_polint_polor2_PC1 <-  list(
  "Volunteering (Yes/No)" = feols(ft_volunt_d ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) 
                                  | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  
  "Local political activism (Yes/No)" = feols(ft_localpol_d ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) 
                                              | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  
  "Voting in federal election (Yes/No)" = feols(votefedel_lead ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)
                                                | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009),
  
  "Party leaning (Yes/No)" = feols(partyleand2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)
                                   | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  
  "Party leaning intensity (0-5)" = feols(partyleanint ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)
                                          | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  
  "Political orientation (0 L – 10 R)" = feols(polor ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) 
                                               | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009),
  
  "Centre left party ID" = feols(centre_left2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) 
                                 | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  
  "Centre right party ID" = feols(centre_right2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) |
                                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df)
)


texreg(fe_main_polint_polor2_PC1)


texreg(fe_main_polint_polor2_PC1, digits = 3,
       label = "tab:fe_main_polint_polor2_PC1",
       caption = "Opportunity moves and political integration and orientation (Labor Market and Economy Component)",
       custom.coef.map = list("pc1_01_wn" = "PC1"),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. All models include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009/10-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E39.tex"))



## Party identification ##

fe_main_partid2_PC1 <-  list(
  "SPD " = feols(spd_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                   pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  "CDU/CSU " = feols(cducsu_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                       pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  "Gruene " = feols(greens_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                      pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  "FDP " = feols(fdp_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                   pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  "Linke" = feols(linke_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  "AfD " = feols(afd_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                   pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2014)
)

texreg(fe_main_partid2_PC1)


texreg(fe_main_partid2_PC1, digits = 3,
       label = "tab:fe_main_partid2_PC1",
       caption = "Opportunity moves and party identification (Labor Market and Economy Component)",
       custom.coef.map = list("pc1_01_wn" = "PC1"),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                            
       custom.note = paste("%stars. Party leanings include coalitions in the political direction of the respective party (i.e., including left coalitions for SPD, Gruene, and Linke; right coalitions for CDU/CSU, FDP, and AfD). All models include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2010-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E40.tex"))

#-----------------------------------------------------------------------------------------------------#
#### 2 | Symmetry of Effects ####
#-----------------------------------------------------------------------------------------------------#

#-----------------------------------------------------------------------------------------------------#
##### 2.1 | Upward move  #####
#-----------------------------------------------------------------------------------------------------#

#-----------------------------------------------------------------------------------------------------#

## Opportunity moves and political integration and orientation ##

# Without multiple movers


# Unbalanced
fe_main_polint_polor2_upmove_ub2_only <-  list(
  "Volunteering (Yes/No)" = feols(ft_volunt_d ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  
  "Local political activism (Yes/No)" = feols(ft_localpol_d ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  
  "Voting in federal election (Yes/No)" = feols(votefedel_lead ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009_upmove_ub2),
  
  "Party leaning (Yes/No)" = feols(partyleand2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| 
                                     pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  
  "Party leaning intensity (0-5)" = feols(partyleanint ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| 
                                            pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  
  "Political orientation (0 L – 10 R)" = feols(polor ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                 pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009_upmove_ub2),
  
  "Centre left party ID" = feols(centre_left2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                   pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  
  "Centre right party ID" = feols(centre_right2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2)
)


texreg(fe_main_polint_polor2_upmove_ub2_only)

texreg(fe_main_polint_polor2_upmove_ub2_only, digits = 3,
       label = "tab:fe_main_polint_polor2_upmove_ub2_only_PC1",
       caption = "Upward opportunity moves and political integration and orientation (Labor Market and Economy Component)",
       custom.coef.map = list('pc1_01_wn' = 'PC1'),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. All models are restricted to one-time upward movers and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009/10-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E41.tex"))



fe_main_partid2_upmove_ub2_only <-  list(
  "SPD" = feols(spd_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  "CDU/CSU" = feols(cducsu_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                      pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  "Gruene" = feols(greens_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                     pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  "FDP" = feols(fdp_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  "Linke" = feols(linke_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  "AfD" = feols(afd_co2 ~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2014_upmove_ub2)
)

texreg(fe_main_partid2_upmove_ub2_only)


texreg(fe_main_partid2_upmove_ub2_only, digits = 3,
       label = "tab:fe_main_partid2_upmove_ub2_only_PC1",
       caption = "Upward opportunity moves and party identification (Labor Market and Economy Component)",
       custom.coef.map = list('pc1_01_wn' = 'PC1'),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                            
       custom.note = paste("%stars. All models are restricted to one-time upward movers and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009/10-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E42.tex"))



#-----------------------------------------------------------------------------------------------------#
##### 2.2 | Downward move  #####
#-----------------------------------------------------------------------------------------------------#

# Unbalanced
fe_main_polint_polor2_downmove_ub2_only <-  list(
  "Volunteering (Yes/No)" = feols(ft_volunt_d ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  
  "Local political activism (Yes/No)" = feols(ft_localpol_d ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  
  "Voting in federal election (Yes/No)" = feols(votefedel_lead ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009_downmove_ub2),
  
  "Party leaning (Yes/No)" = feols(partyleand2 ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| 
                                     pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  
  "Party leaning intensity (0-5)" = feols(partyleanint ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| 
                                            pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  
  "Political orientation (0 L – 10 R)" = feols(polor ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                 pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009_downmove_ub2),
  
  "Centre left party ID" = feols(centre_left2 ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                   pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  
  "Centre right party ID" = feols(centre_right2 ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2)
)


texreg(fe_main_polint_polor2_downmove_ub2_only)

texreg(fe_main_polint_polor2_downmove_ub2_only, digits = 3,
       label = "tab:fe_main_polint_polor2_downmove_ub2_only_PC1",
       caption = "Downward opportunity moves and political integration and orientation (Labor Market and Economy Component)",
       custom.coef.map = list('pc1_01_wn_rc' = 'PC1 (rev)'),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. All models are restricted to one-time downward movers and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009/10-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E43.tex")
)



fe_main_partid2_downmove_ub2_only <-  list(
  "SPD" = feols(spd_co2 ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  "CDU/CSU" = feols(cducsu_co2 ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                      pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  "Gruene" = feols(greens_co2 ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                     pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  "FDP" = feols(fdp_co2 ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  "Linke" = feols(linke_co2 ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  "AfD" = feols(afd_co2 ~ pc1_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2014_downmove_ub2)
)

texreg(fe_main_partid2_downmove_ub2_only)


texreg(fe_main_partid2_downmove_ub2_only, digits = 3,
       label = "tab:fe_main_partid2_downmove_ub2_only_PC1",
       caption = "Downward opportunity moves and party identification (Labor Market and Economy Component)",
       custom.coef.map = list('pc1_01_wn_rc' = 'PC1 (rev)'),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                            
       custom.note = paste("%stars. All models are restricted to one-time downward movers and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009/10-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E44.tex"))



#-------------------------------------------------------------------------------# 
#### 3 | Economic and Cultural Mechanisms ####

#-------------------------------------------------------------------------------# 

##### 3.1 | Economic #####


# Main #
econ_DVs <- c("ln_pglabgro2", "pgisei08", "worr_wpsec")
# , "ue_d" --> increases!

names_econ_DVs <- c(ln_pglabgro2 = "Log gross monthly earnings", 
                    pgisei08 = "ISEI-score",
                    worr_wpsec = "Worries about job security"#, 
                    #income = "Equiv. HH income"
)


fe_mech_econ <- list()

# Loop over econ CVs
for (econ_DV in econ_DVs) {
  
  # Define model
  formula <- as.formula(paste(econ_DV, "~ pc1_01_wn + pgexpft + pgexpft^2 + as.factor(educ_h) + as.factor(hhtype)| pid + syear"))
  
  # Run regression 
  fe_mech_econ[[names_econ_DVs[[econ_DV]]]] <- feols(formula, panel.id = ~pid + syear, cluster = "krs", data = df_2009)
}

texreg(fe_mech_econ)
texreg(fe_mech_econ, digits = 3,
       label = "tab:fe_mech_econ_PC1",
       caption = "Opportunity moves: Socio-economic Outcomes (Labor Market and Economy Component)",
       custom.coef.map = list('pc1_01_wn' = 'PC1'),
       custom.gof.rows = list("Individual fixed-effects" = rep("YES", length(fe_mech_econ)), 
                              "Time fixed-effect" = rep("YES", length(fe_mech_econ))),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. All models include work experience, work experience squared, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E45a.tex"))


#------------------------------------------------------------------------------#
##### 3.2 | Cultural #####
#------------------------------------------------------------------------------#

# DVs on cultural variables

cult_DVs <- c("ft_opera_d", "ft_cinema_d","ft_artmus_d") # 

names_cult_DVs <- c(ft_opera_d = "Cultural events (dummy)", 
                    ft_cinema_d = "Cinema, concerts, clubs (dummy)", 
                    ft_artmus_d = "Artistic/musical activities (dummy)"
)

# , ft_index_cult = "Cultural activities (index)"

fe_mech_culture <- list()

# Loop over cult CVs
for (cult_DV in cult_DVs) {
  
  # Define model
  formula <- as.formula(paste(cult_DV, "~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| pid + syear"))
  
  # Run regression 
  fe_mech_culture[[names_cult_DVs[[cult_DV]]]] <- feols(formula, panel.id = ~pid + syear, cluster = "krs", data = df_2009)
}


texreg(fe_mech_culture)
texreg(fe_mech_culture, digits = 3,
       label = "tab:fe_mech_culture_PC1",
       caption = "Opportunity moves: Cultural Outcomes (Labor Market and Economy Component)",
       custom.coef.map = list('pc1_01_wn' = 'PC1'),
       custom.gof.rows = list("Individual fixed-effects" = rep("YES", length(fe_mech_culture)), 
                              "Time fixed-effect" = rep("YES", length(fe_mech_culture))),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. All models are linear probability models and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E45b.tex"))


#------------------------------------------------------------------------------#
##### 3.3 | Upward Econ #####
#------------------------------------------------------------------------------#


# Main #
econ_DVs <- c("ln_pglabgro2", "pgisei08", "worr_wpsec")

names_econ_DVs <- c(ln_pglabgro2 = "Log gross monthly earnings", 
                    pgisei08 = "ISEI-score",
                    worr_wpsec = "Worries about job security"
)

fe_mech_econ_upmove_ub2 <- list()

# Loop over econ CVs
for (econ_DV in econ_DVs) {
  
  # Define model
  formula <- as.formula(paste(econ_DV, "~ pc1_01_wn + pgexpft + pgexpft^2 + as.factor(educ_h) + as.factor(hhtype)| pid + syear"))
  
  # Run regression 
  fe_mech_econ_upmove_ub2[[names_econ_DVs[[econ_DV]]]] <- feols(formula, panel.id = ~pid + syear, 
                                                                cluster = "krs", data = df_2009_upmove_ub2)
}


texreg(fe_mech_econ_upmove_ub2)


texreg(fe_mech_econ_upmove_ub2, digits = 3,
       label = "tab:fe_mech_econ_upmove_ub2_PC1",
       caption = "Upward opportunity moves: Socio-economic Outcomes (Labor Market and Economy Component)",
       custom.coef.map = list('pc1_01_wn' = 'PC1'),
       custom.gof.rows = list("Individual fixed-effects" = rep("YES", length(fe_mech_econ_upmove_ub2)), 
                              "Time fixed-effect" = rep("YES", length(fe_mech_econ_upmove_ub2))),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. The sample is restricted to upward moves only. All models include work experience, work experience squared, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E46a.tex"))


#------------------------------------------------------------------------------#
##### 3.4 | Upward Cult #####
#------------------------------------------------------------------------------#

cult_DVs <- c("ft_opera_d", "ft_cinema_d","ft_artmus_d")

names_cult_DVs <- c(ft_opera_d = "Cultural events (dummy)", 
                    ft_cinema_d = "Cinema, concerts, clubs (dummy)", 
                    ft_artmus_d = "Artistic/musical activities (dummy)"
)

fe_mech_culture_upmove_ub2 <- list()

# Loop over cult CVs
for (cult_DV in cult_DVs) {
  
  # Define model
  formula <- as.formula(paste(cult_DV, "~ pc1_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| pid + syear"))
  
  # Run regression 
  fe_mech_culture_upmove_ub2[[names_cult_DVs[[cult_DV]]]] <- feols(formula, panel.id = ~pid + syear, 
                                                                   cluster = "krs", data = df_2009_upmove_ub2)
}


texreg(fe_mech_culture_upmove_ub2, digits = 3,
       label = "tab:fe_mech_culture_upmove_ub2_PC1",
       caption = "Upward opportunity moves: Cultural Outcomes (Labor Market and Economy Component)",
       custom.coef.map = list('pc1_01_wn' = 'PC1'),
       custom.gof.rows = list("Individual fixed-effects" = rep("YES", length(fe_mech_culture_upmove_ub2)), 
                              "Time fixed-effect" = rep("YES", length(fe_mech_culture_upmove_ub2))),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. The sample is restricted to upward moves only. All models are linear probability models and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E46b.tex"))



#-----------------------------------------------------------------------------------------------------#
# Remove all model lists from storage
rm(list = ls(pattern = "^fe_"))

#-----------------------------------------------------------------------------------------------------#



